//
//  ViewController.m
//  26-Masonry-代码约束
//
//  Created by 王道林 on 16/8/18.
//  Copyright © 2016年 王道林. All rights reserved.
//
#define COLORAUTO [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0]

#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 1. 使用Masonry,   不用给初始frame
    UIView *view = [UIView new];
    view.backgroundColor = COLORAUTO;
    [self.view addSubview:view];
    
    // 设置改视图的约束
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
      //  make.left.right.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    
    // 添加蓝色视图, 宽高个100, 居中显示
    
    UIView *blueView = [UIView new];
    blueView.backgroundColor = [UIColor blueColor];
    [view addSubview:blueView];
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5f);
        make.height.mas_equalTo(100);
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
    }];
    
    // 添加黄色视图, 宽高与蓝色相同, 与蓝色相聚10;
    
    UIView *yellowView = [UIView new];
    yellowView.backgroundColor = [UIColor yellowColor];
    [view addSubview:yellowView];
    [yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
    //    make.width.height .mas_equalTo(blueView);
        make.width.centerX.height.mas_equalTo(blueView);
        make.top.mas_equalTo(blueView.mas_bottom).mas_offset(10);
        
    }];
    
    // 系统的约束
    //greenview.left = self.view.left * 1.0f + 0;
//    [NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
